﻿@{
    Layout = "~/Views/Shared/_FormWhite.cshtml";
}
@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment HostingEnvironment
@section header{
    <link href="@Url.Content("~/lib/summernote/0.8.15/summernote.min.css")" rel="stylesheet" type="text/css">
    <script src='@Url.Content("~/lib/summernote/0.8.15/summernote.js")' type="text/javascript"></script>
    <script src='@Url.Content("~/lib/summernote/0.8.15/lang/summernote-zh-CN.min.js")' type="text/javascript"></script>

    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/imageupload/1.0/css/imgup.min.css"))
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/imageupload/1.0/js/imgup.min.js"))

    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/bootstrap.tagsinput/0.8.0/bootstrap-tagsinput.min.css"))
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/bootstrap.tagsinput/0.8.0/bootstrap-tagsinput.min.js"))
}

<div class="wrapper animated fadeInRight">
    <form id="form" class="form-horizontal m">
        <div class="form-group">
            <label class="col-sm-2 control-label ">网点名称 <font class="red"> *</font> </label>
            <div class="col-sm-10">
                <input id="newsTitle" col="NewsTitle" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">经度<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="newsX" col="NewsX" type="text" class="form-control" />
            </div>
            <label class="col-sm-2 control-label ">维度<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="newsY" col="NewsY" type="text" class="form-control" />
            </div>

        </div>
        <div class="form-group">
            @*<label class="col-sm-2 control-label ">作者<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="newsAuthor" col="NewsAuthor" type="text" class="form-control" />
            </div>*@
            <label class="col-sm-2 control-label ">排序<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="newsSort" col="NewsSort" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group" style="display:none;">
            <label class="col-sm-2 control-label ">服务网点</label>
            <div class="col-sm-8">
                <div id="provinceId" col="ProvinceId"></div>
               
            </div>
        </div>
        
        <div class="form-group">
            <label class="col-sm-2 control-label ">电话</label>
            <div class="col-sm-10">
                <input id="newsTag" col="NewsTag" type="text" class="form-control" />
            </div>
        </div>
        
        <div class="form-group">
            <label class="col-sm-2 control-label ">地址 </label>
            <div class="col-sm-10">
                <input id="newsContent" col="NewsContent" type="text" class="form-control" />
                
            </div>
        </div>
    </form>
</div>

<script type="text/javascript">
    var id = ys.request("id");
    $(function () {
        laydate.render({ elem: '#newsDate', type: 'datetime', format: 'yyyy-MM-dd HH:mm' });        
        $("#provinceId").ysComboBox({
            url: '@Url.Content("~/SystemManage/Area/GetListJson1?AreaLevel=1")',
            dataName: "Result",
            key: "AreaCode",
            value: "AreaName",
            class: "form-control",
          
        });
        //$('#newsTag').tagsinput({ trimValue: true });

        //$("#newsType").ysComboBox({
        //    data: top.getDataDict("NewsType"),
        //    key: "DictKey",
        //    value: "DictValue",
        //    class: "form-control"
        //});

        //$('#newsContent').summernote({
        //    height: '220px',
        //    lang: 'zh-CN',
        //    dialogsInBody: true,
        //    callbacks: {
        //        onImageUpload: function (files, editor, welEditable) {
        //            uploadNewsImage(files[0], editor, welEditable);
        //        }
        //    }
        //});

       // $("#thumbImage").imageUpload({ uploadImage: 'uploadThumbImage', limit: 1, context: ctx });

        getForm();

        $("#form").validate({
            rules: {
                newsTitle: { required: true },

            }
        });
    });

    function getForm() {
        console.log(id)
        if (id > 0) {
            ys.ajax({
                url: '@Url.Content("~/OrganizationManage/Network/GetFormJson")' + '?id=' + id,
                type: "get",
                success: function (obj) {
                    if (obj.Tag == 1) {

                        $("#form").setWebControls(obj.Result);

                        $("#bnImage").imageUpload("setImageUrl", obj.Result.BnImage);

                    }
                }
            });
        }
        else {

            ys.ajax({
                url: '@Url.Content("~/OrganizationManage/Network/GetFormJson")',
                type: "get",
                success: function (obj) {
                    if (obj.Tag == 1) {
                        var defaultData = {};

                        defaultData.NewsSort = obj.Result;
                        $("#form").setWebControls(defaultData);
                    }
                }
            });
        }
    }

    function saveForm(index) {
        console.log("来了")
        if ($("#form").validate().form()) {
            var postData = $("#form").getWebControls({ Id: id });
            //postData.NewsContent = $("#newsContent").summernote('code');
            postData.ProvinceId = ys.getLastValue(postData.ProvinceId);
            //postData.ThumbImage = $("#thumbImage").imageUpload("getImageUrl");
            //console.log(postData)
            console.log(123+postData.provinceId)
            ys.ajax({
                url: '@Url.Content("~/OrganizationManage/Network/SaveFormJson")',
                type: "post",
                data: postData,
                success: function (obj) {
                    if (obj.Tag == 1) {
                        ys.msgSuccess(obj.Message);
                        parent.searchGrid();
                        parent.layer.close(index);
                    }
                    else {
                        ys.msgError(obj.Message);
                    }
                }
            });
        }
    }

    function uploadNewsImage(file, editor, welEditable) {
        var formdata = new FormData();
        formdata.append("fileList", file);
        ys.ajaxUploadFile({
            url: '@GlobalContext.SystemConfig.ApiSite' + '/File/UploadFile?fileModule=@UploadFileType.News.ParseToInt()',
            data: formdata,
            success: function (obj) {
                if (obj.Tag == 1) {
                    $("#newsContent").summernote('insertImage', '@GlobalContext.SystemConfig.ApiSite' + obj.Result, '/');
                }
                else {
                    ys.msgError(obj.Message);
                }
            }
        })
    }

    function uploadThumbImage(file, callback) {
        var formdata = new FormData();
        formdata.append("fileList", file);
        ys.ajaxUploadFile({
            url: '@GlobalContext.SystemConfig.ApiSite' + '/File/UploadFile?fileModule=@UploadFileType.News.ParseToInt()',
            data: formdata,
            success: function (obj) {
                if (obj.Tag == 1) {
                    if (callback) {
                        callback('@GlobalContext.SystemConfig.ApiSite' + obj.Result);
                    }
                }
                else {
                    ys.msgError(obj.Message);
                }
            }
        })
    }
</script>

